//
//  FPHeadAanimation.m
//  FilmParadise
//
//  Created by lanou3g on 15/7/17.
//  Copyright (c) 2015年 DLYgroup. All rights reserved.
//

#import "FPHeadAanimation.h"
#import "FPAanimationModel.h"
@implementation FPHeadAanimation

//解析数据
+ (void)analysisHA:(UITableView *)tableView
{
    NSMutableArray *tempAttay = [NSMutableArray array];

    NSURL *url = [NSURL URLWithString:@"http://api.m.mtime.cn/PageSubArea/PullMovieAdvWordAndCouponActivities.api?locationId=292"];
    //创建请求对象
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
    //开启异步联接 用队列的形式进行一步请求数据
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (!data)
        {
            return ;
        }
        //请求的所有数据已经全部接受完成的时候 ,才会执行Block快里的方法 此时data就是我们请求下来的数据它会自动传回到这个参数上面
        NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSArray *advWordLists = dic[@"advWordList"];
        for (NSDictionary *smallDic in advWordLists)
        {
            FPAanimationModel *model = [FPAanimationModel fpAnimationModelWithDictionary:smallDic];
            [tempAttay addObject:model];
        }
        
        NSInteger random = arc4random()%tempAttay.count;
        FPAanimationModel *model = tempAttay[random];
        tableView.header.height = 60;
        NSString *str = [NSString stringWithFormat:@"%@\n%@",model.movieName,model.word];
        tableView.header.stateLabel.numberOfLines = 0;
        tableView.header.stateLabel.height = 30;
        tableView.header.stateLabel.font = [UIFont systemFontOfSize:11];
        tableView.header.stateLabel.textColor = [UIColor blackColor];
        tableView.header.updatedTimeLabel.hidden = YES;
        [tableView.header setTitle:str forState:MJRefreshHeaderStateIdle];
        [tableView.header setTitle:str forState:MJRefreshHeaderStatePulling];
        [tableView.header setTitle:str forState:MJRefreshHeaderStateRefreshing];
        
        [tableView.header endRefreshing];
    }];
    
}

@end
